package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 基于插件的  延迟消息
 */
@Configuration
public class DelayedMqConfig {

    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";


    //交换机 延迟的交换机 （保存长达2小时以上消息）
    @Bean
    public CustomExchange customExchange(){
        Map<String, Object> arguments  = new HashMap<>();
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(exchange_delay,"x-delayed-message",true,
                false,arguments);
    }

    //
    @Bean
    public Queue queue12(){
        return QueueBuilder.durable(queue_delay_1).build();
    }

    @Bean
    public Binding bindingQueue12ToCustomExchange(){
        return BindingBuilder.bind(queue12()).to(customExchange()).
                with(routing_delay).noargs();
    }
}
